import pymysql

conn = pymysql.connect(host="localhost", user="root", passwd="zwq123456", db='cnblog', charset='utf8', port=3306)

# 创建游标

cursor = conn.cursor()
# 执行sql语句
cursor.execute("""create table if not exists t_sales(
                id int primary key auto_increment not null,
                 nickName varchar(128) not null,
                 color varchar(128) not null,
                  size varchar(128) not null, 
                  comment text not null,
                  saledate varchar(128) not null)engine=InnoDB default charset=utf8;""")

# cursor.execute("""insert into t_sales(nickName,color,size,comment,saledate)
# values('%s','%s','%s','%s','%s');""" % ("zack", "黑色", "L", "大小合适", "2019-04-20"))

cursor.execute("""insert into t_sales(nickName,color,size,comment,saledate) 
                values(%s,%s,%s,%s,%s);""", ("zack", "黑色", "L", "大小合适", "2019-04-20"))
# 提交
conn.commit()
# 关闭游标
cursor.close()
# 关闭连接
conn.close()